load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/sql/colexecop:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "colexecspan",
    srcs = [
        "span_assembler.go",
        ":gen-exec",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecspan",  # keep
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/col/coldata",  # keep
        "//pkg/col/coldataext",  # keep
        "//pkg/col/typeconv",  # keep
        "//pkg/keys",  # keep
        "//pkg/roachpb",  # keep
        "//pkg/sql/catalog",  # keep
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/descpb",  # keep
        "//pkg/sql/catalog/fetchpb",
        "//pkg/sql/colexecerror",  # keep
        "//pkg/sql/colmem",  # keep
        "//pkg/sql/execinfra/execreleasable",
        "//pkg/sql/rowenc",  # keep
        "//pkg/sql/rowenc/keyside",  # keep
        "//pkg/sql/sem/tree",  # keep
        "//pkg/sql/types",  # keep
        "//pkg/util",  # keep
        "//pkg/util/duration",  # keep
        "//pkg/util/encoding",  # keep
        "@com_github_cockroachdb_apd_v3//:apd",  # keep
        "@com_github_cockroachdb_errors//:errors",  # keep
    ],
)

go_test(
    name = "colexecspan_test",
    srcs = [
        "main_test.go",
        "span_assembler_test.go",
    ],
    embed = [":colexecspan"],  # keep
    deps = [
        "//pkg/col/coldata",
        "//pkg/col/coldataext",
        "//pkg/col/coldatatestutils",
        "//pkg/keys",
        "//pkg/roachpb",
        "//pkg/security/username",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/fetchpb",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/colconv",
        "//pkg/sql/colexec/colexectestutils",
        "//pkg/sql/colexecerror",
        "//pkg/sql/colmem",
        "//pkg/sql/execinfra",
        "//pkg/sql/rowenc",
        "//pkg/sql/sem/eval",
        "//pkg/sql/span",
        "//pkg/sql/types",
        "//pkg/testutils/skip",
        "//pkg/util/intsets",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/randutil",
    ],
)

# Map between target name and relevant template.
targets = [
    ("span_encoder.eg.go", "span_encoder_tmpl.go"),
]

# Define a file group for all the .eg.go targets.
eg_go_filegroup(
    name = "gen-exec",
    targets = targets,
)

# Define gen rules for individual eg.go files.
gen_eg_go_rules(targets)

disallowed_imports_test(
    "colexecspan",
    [
        "//pkg/sql/colexec",
        "//pkg/sql/colexec/colexecagg",
        "//pkg/sql/colexec/colexecbase",
        "//pkg/sql/colexec/colexechash",
        "//pkg/sql/colexec/colexecjoin",
        "//pkg/sql/colexec/colexecproj",
        "//pkg/sql/colexec/colexecprojconst",
        "//pkg/sql/colexec/colexecsel",
        "//pkg/sql/colexec/colexecwindow",
        "//pkg/sql/execinfra",
    ],
)
